package com.example.recyclerviewproject;

import android.os.Bundle;
import android.view.View;
import android.view.Window;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.OrientationHelper;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

public class RecyclerViewAct extends AppCompatActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recyclerview_layout);
        // No Titlebar
        getSupportActionBar().hide();
        //*初始化RecyclerView控件
        RecyclerView mRecyclerView = findViewById(R.id.mRecyclerView);
        //*创建布局管理器
        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        //设置为垂直布局，这也是默认的
        layoutManager.setOrientation(RecyclerView. VERTICAL);
        //水平
      //  layoutManager.setOrientation(RecyclerView.HORIZONTAL);
        //网格布局
      //  GridLayoutManager layoutManager2 = new GridLayoutManager(this,3);
        //*设置布局管理器
        mRecyclerView.setLayoutManager(layoutManager);
        //准备数据
        List<ItemBean> list = new ArrayList<>();
        for (int i = 1; i <=40; i++) {
            ItemBean itemBean = new ItemBean();
            itemBean.setImageInt(R.mipmap.new_icon);
            itemBean.setTitle("标题"+i);
            itemBean.setContent("内容===="+i);
            list.add(itemBean);
        }
        //*创建适配器
        MyAdapter myAdapter = new MyAdapter(this);
        //*给适配器传数据作为列表数据
        myAdapter.setList(list);
        //*设置RecyclerView的适配器
        mRecyclerView.setAdapter(myAdapter);
       DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(this, RecyclerView.VERTICAL);
      mRecyclerView.addItemDecoration(dividerItemDecoration);


    }
}
